package o2o.web.actions.order.other;

import com.jinyou.utils.common.AjaxResult;
import com.jinyou.utils.common.JYMathDoubleUtils;
import com.jinyou.utils.common.JYPageUtils;
import com.jinyou.utils.common.ValidateUtil;
import o2o.cache.order.OrderInfoMemory;
import o2o.cache.postman.CityPostmanMemory;
import o2o.cache.shop.ShopMemory;
import o2o.cache.sys.SysConfigDepositMemory;
import o2o.cache.user.UserInfoMemory;
import o2o.cache.user.UserOnlineImpl;
import o2o.cache.wallet.UserWalletMemory;
import o2o.config.dao.UserDaoSql;
import o2o.dao.PO.PojoTables;
import o2o.dao.PO.common.ResultInfo;
import o2o.dao.PO.common.UserType;
import o2o.dao.PO.order.*;
import o2o.postman.model.CityPostman;
import o2o.company.model.ShopInfo;
import o2o.dao.PO.user.UserInfo;
import o2o.dao.PO.wallet.UserWallet;
import o2o.dao.VO.order.ORDER_RELAY_TYPE;
import o2o.system.data.SYS_SETTINGS;
import o2o.web.actions.order.OrderMan;
import o2o.web.actions.sys.GrabOrderModeMan;
import o2o.web.actions.user.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

//import jdk.nashorn.internal.runtime.RewriteException;

//配送员转单记录
@Controller
public class OrderChangePostmanAction {


    //配送员转单
    @RequestMapping(method = RequestMethod.POST, value = "/postman/order/change")
    @ResponseBody
    public String order_postman(String token, String orderNo, String toUsername) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        if (ValidateUtil.isNull(orderNo)) {
            return AjaxResult.errorResult("请选择订单");
        }

        ResultInfo resultInfo = OrderMan.changePostman(orderNo, user.getUsername(), toUsername, user.getUsername());
        if (null == resultInfo) {
            return AjaxResult.errorResult("转单失败，请稍后重试。");
        } else if (!resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }

        return AjaxResult.successResult();
    }


    //配送员接单
    @RequestMapping(method = RequestMethod.POST, value = "/postman/order/change/sure")
    @ResponseBody
    public String order_postman_sure(String token, String orderNo) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        CityPostman postman = CityPostmanMemory.getInstance().getPostman(user.getUsername());
        if (null == postman) {
            return AjaxResult.errorResult("未查询到您的信息，无法操作");
        }

        if (0 == postman.getIsWork()) {
            return AjaxResult.errorResult("请先上班");
        }

        if (ValidateUtil.isNull(orderNo)) {
            return AjaxResult.errorResult("请选择订单");
        }

        ResultInfo resultInfo = OrderMan.postmanSureOrRefuse(orderNo, user.getUsername(), OrderPostmanInfo.SURE);
        if (null == resultInfo) {
            return AjaxResult.errorResult("接受订单失败，请稍后重试。");
        } else if (!resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }

        return AjaxResult.successResult();
    }


    //配送员拒绝接单
    @RequestMapping(method = RequestMethod.POST, value = "/postman/order/change/refuse")
    @ResponseBody
    public String order_postman_refuse(String token, String orderNo) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        if (ValidateUtil.isNull(orderNo)) {
            return AjaxResult.errorResult("请选择订单");
        }
        
        ResultInfo resultInfo = OrderMan.postmanSureOrRefuse(orderNo, user.getUsername(), OrderPostmanInfo.REFUSE);
        if (null == resultInfo) {
            return AjaxResult.errorResult("拒绝订单失败，请稍后重试。");
        } else if (!resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }

        return AjaxResult.successResult();
    }


    //管理后台转单
    @RequestMapping(method = RequestMethod.POST, value = "/admin/order/change")
    @ResponseBody
    public String admin_order_postman(String token, String orderNo, String fromUsername, String toUsername) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        if (!User.hasAdminAuth(user.getUserType())) {
            return AjaxResult.errorResult("您无操作权限");
        }

        if (ValidateUtil.isNull(orderNo)) {
            return AjaxResult.errorResult("请选择订单");
        }

        ResultInfo resultInfo = OrderMan.changePostman(orderNo, fromUsername, toUsername, user.getUsername(), true);
        if (null == resultInfo) {
            return AjaxResult.errorResult("转单失败，请稍后重试。");
        } else if (!resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }

        return AjaxResult.successResult();
    }

    //管理后台转单
    @RequestMapping(method = RequestMethod.POST, value = "/admin/order/disPatch-state")
    @ResponseBody
    public String admin_order_dispatch_state(String orderNo, String token, @RequestParam(defaultValue = "1") Integer disPatchState) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (!User.hasAdminAuth(user.getUserType())) {
            return AjaxResult.errorResult("您无操作权限");
        }
        if (ValidateUtil.isNull(orderNo)) {
            return AjaxResult.errorResult("请选择订单");
        }
        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (orderInfo == null) {
            return AjaxResult.errorResult("订单不存在,请核实");
        }
        if (GrabOrderModeMan.getGrabOrderMode(orderInfo.getAgentId()) != GRAB_ORDER_MODE.DISPATCH_FIRST_TO_OTHER) {
            return AjaxResult.errorResult("当前订单模式下不允许操作");
        }
        if (disPatchState != ORDER_DISPATCH_STATE.ORDER_DISPATCH && disPatchState != ORDER_DISPATCH_STATE.ORDER_GRAB) {
            return AjaxResult.errorResult("未知的的操作模式");
        }
        StringBuilder sql = new StringBuilder();
        sql.append(" update ").append(PojoTables.OrderInfo)
                .append(" set updateUser ='").append(user.getUsername()).append("'")
                .append(",dispatchState =").append(disPatchState)
                .append(" where delFlag = 0 and orderNo = '").append(orderNo).append("'");
        try {
            UserDaoSql.getInstance().executeBySql(sql.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("操作失败,请稍后重试");
        }
        OrderInfoMemory.getInstance().modifyStatus(orderNo);
//        if (disPatchState == ORDER_DISPATCH_STATE.ORDER_GRAB) {
//            // 极光推送
//        }
        return AjaxResult.successResult();
    }

    //---------------好管家
    //转抢
    @RequestMapping(method = RequestMethod.POST, value = "/order/shop/relay")
    @ResponseBody
    public String order_postman_relay(String token, String sysAppKey, String orderNo) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (null == shopInfo) {
            return AjaxResult.errorResult("您的店铺已不存在，请查证");
        }

        if (null != SYS_SETTINGS.SHOP_MUST_DEPOSIT && 0 == 1 - SYS_SETTINGS.SHOP_MUST_DEPOSIT) {
            // 必须缴纳
            //验证押金金额是否满足
            UserWallet userWallet = UserWalletMemory.getInstance().getWallet(user.getUsername());
            if (null == userWallet) {
                return AjaxResult.errorResult("您还未缴纳押金，请先缴纳押金");
            }
            if (null == userWallet.getDepositMoney() || userWallet.getDepositMoney() <= 0) {
                return AjaxResult.errorResult("您还未缴纳押金，请先缴纳押金！");
            }
            //必须缴纳的押金金额
            Double money = SysConfigDepositMemory.getInstance().getByType(UserType.SHOP_OWNER);
            if (null == money) {
                money = 0d;
            }

            if (JYMathDoubleUtils.sub(userWallet.getDepositMoney(), money) < 0) {
                return AjaxResult.errorResult("您缴纳的押金不足，请先缴纳押金");
            }
        }

        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (null == orderInfo) {
            return AjaxResult.errorResult("当前订单不存在");
        }

        if (null != orderInfo.getOrderType() && 0 == ORDER_TYPE.SHOP_GOODS - orderInfo.getOrderType()) {
            if (null == shopInfo.getIsSelfPost() || 0 != 1 - shopInfo.getIsSelfPost()) {
                return AjaxResult.errorResult("仅限自配送商家使用此功能");
            }
        }

        //验证订单状态
        if (0 == ORDER_STATUS.SHOP_SURE - orderInfo.getOrderStatus()
                || 0 == ORDER_STATUS.WAIT_REPAIR - orderInfo.getOrderStatus()
        ) {

        } else {
            return AjaxResult.errorResult("该状态下不允许操作");
        }

        if (ValidateUtil.isNotNull(orderInfo.getPostManUsername())) {
            return AjaxResult.errorResult("已有配送员，无法转抢");
        }

        //当前订单是否转抢中
        if (0 == ORDER_RELAY_TYPE.ING - orderInfo.getIsReGrab() || 0 == ORDER_RELAY_TYPE.OVER - orderInfo.getIsReGrab()) {
            return AjaxResult.errorResult("该订单已转抢，不允许再次操作");
        }

        //转抢
        StringBuffer sb = new StringBuffer();
        sb.append("update ").append(PojoTables.OrderInfo).append(" set isReGrab=").append(ORDER_RELAY_TYPE.ING).append(",updateUser='").append(user.getUsername())
                .append("' where delFlag = 0 and orderNo = '").append(orderNo).append("'");
        try {
            UserDaoSql.getInstance().executeUpdateBySql(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
            return AjaxResult.errorResult("转抢失败，请稍后再试");
        }

        //修改订单缓存
        OrderInfoMemory.getInstance().modifyStatus(orderNo);


        return AjaxResult.successResult();
    }

    //  todo  配送公司转单记录 转单记录
    @RequestMapping(method = RequestMethod.POST, value = "/company/order/change/records")
    @ResponseBody
    public String comopany_order_change_records(String token, Long companyId, String city, String orderNo, String fromUsername, Integer page, Integer size) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNotAbsInteger(page)) {
            page = 1;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT a.*, b.`shopCity` shopCity FROM ").append(PojoTables.ORDER_POSTMAN).append(" a")
                .append(" LEFT JOIN ").append(PojoTables.OrderInfo).append(" b on a.orderNo = b.orderNo")
                .append(" where a.delFlag = 0 and b.delFlag = 0");

        if (ValidateUtil.isNotNull(orderNo)) {
            sb.append(" and a.orderNo like '%").append(orderNo).append("%'");
        }

        if (ValidateUtil.isNotNull(fromUsername)) {
            sb.append(" and a.fromUsername like '%").append(fromUsername).append("%'");
        }

        if (ValidateUtil.isNotNull(fromUsername)) {
            sb.append(" and a.fromUsername like '%").append(fromUsername).append("%'");
        }

        if (ValidateUtil.isID(companyId)) {
            sb.append(" and b.grabCompanyId  = ").append(companyId);
        }
        List<OrderPostmanInfo> list = null;
        try {
            list = (List<OrderPostmanInfo>) UserDaoSql.getInstance().list(OrderPostmanInfo.class, sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (ValidateUtil.isAbsList(list)) {
            JYPageUtils.PageList pageList = JYPageUtils.getList(list, page, size);
            if (null != pageList && ValidateUtil.isAbsList(pageList.list)) {
                List<OrderPostmanInfo> voList = new ArrayList<>();
                for (OrderPostmanInfo orderPostmanInfo : (List<OrderPostmanInfo>) pageList.list) {
                    if (orderPostmanInfo == null) {
                        continue;
                    }
                    if (ValidateUtil.isNull(orderPostmanInfo.getFromName())) {
                        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(orderPostmanInfo.getFromUsername());
                        if (null != userInfo) {
                            orderPostmanInfo.setFromName(userInfo.getName());
                        }
                    }
                    if (ValidateUtil.isNull(orderPostmanInfo.getToName())) {
                        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(orderPostmanInfo.getToUsername());
                        if (null != userInfo) {
                            orderPostmanInfo.setToName(userInfo.getName());
                        }
                    }
                    voList.add(orderPostmanInfo);
                }
                return AjaxResult.successResult(voList, pageList.totalCount);
            }
        }
        return AjaxResult.successResult(null, 0);
    }

    // 转单记录
    @RequestMapping(method = RequestMethod.POST, value = "/admin/order/change/records")
    @ResponseBody
    public String order_change_records(String token, String orderNo, String fromUsername, String city, Integer page, Integer size) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT a.*, b.`shopCity` shopCity FROM ").append(PojoTables.ORDER_POSTMAN).append(" a")
                .append(" LEFT JOIN ").append(PojoTables.OrderInfo).append(" b on a.orderNo = b.orderNo")
                .append(" where a.delFlag = 0 and b.delFlag = 0");

        if (ValidateUtil.isNotNull(orderNo)) {
            sb.append(" and a.orderNo like '%").append(orderNo).append("%'");
        }
        if (ValidateUtil.isNotNull(fromUsername)) {
            sb.append(" and a.fromUsername like '%").append(fromUsername).append("%'");
        }
        if (ValidateUtil.isNotNull(city)) {
            sb.append(" and b.shopCity like '%").append(city).append("%'");
        }
        List<OrderPostmanInfo> list = null;
        try {
            list = (List<OrderPostmanInfo>) UserDaoSql.getInstance().list(OrderPostmanInfo.class, sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (ValidateUtil.isAbsList(list)) {
            if (ValidateUtil.isNotAbsInteger(page)) {
                page = 1;
            }
            if (ValidateUtil.isNotAbsInteger(size)) {
                size = 20;
            }
            JYPageUtils.PageList pageList = JYPageUtils.getList(list, page, size);
            if (null != pageList && null != pageList.list && pageList.list.size() > 0) {
                List<OrderPostmanInfo> voList = new ArrayList<>();
                for (int i = 0; i < pageList.list.size(); i++) {
                    OrderPostmanInfo orderPostmanInfo = (OrderPostmanInfo) pageList.list.get(i);
                    if (orderPostmanInfo == null) {
                        continue;
                    }
                    if (ValidateUtil.isNull(orderPostmanInfo.getFromName())) {
                        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(orderPostmanInfo.getFromUsername());
                        if (null != userInfo) {
                            orderPostmanInfo.setFromName(userInfo.getName());
                        }
                    }
                    if (ValidateUtil.isNull(orderPostmanInfo.getToName())) {
                        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(orderPostmanInfo.getToUsername());
                        if (null != userInfo) {
                            orderPostmanInfo.setToName(userInfo.getName());
                        }
                    }
                    voList.add(orderPostmanInfo);
                }

                return AjaxResult.successResult(pageList.totalCount, voList.size(), voList);
            }
        }
        return AjaxResult.successResult(0, 0, null);
    }

    // 骑手是否在指定集合中
    public static boolean postmanIsInHashSetPostman(String postman, HashSet<String> set) {
        if (ValidateUtil.isNull(postman) || set == null || set.size() == 0) {
            return false;
        }
        for (String pU : set) {
            if (pU.contains(postman)) {
                return true;
            }
        }
        return false;
    }


//    private ResultInfo changePostman(String orderNo, String fromUsername, String toUsername, String opUsername) {
//        return changePostman(orderNo, fromUsername, toUsername, opUsername, false);
//    }
//
//    //------------------------
//    private ResultInfo changePostman(String orderNo, String fromUsername, String toUsername, String opUsername, boolean isSystem) {
//        if (ValidateUtil.isNull(orderNo) || ValidateUtil.isNull(fromUsername) || ValidateUtil.isNull(toUsername)) {
//            return new ResultInfo("信息不完整，请稍后再试");
//        }
//
//        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
//        if (null == orderInfo) {
//            return new ResultInfo("订单不存在，请稍后再试");
//        }
//
//        String tmpUsername = "";
//        if (toUsername.length() < 11) {
//            List<CityPostman> list = CityPostmanMemory.getInstance().listOfCity(orderInfo.getShopCity());
//            if (!ValidateUtil.isAbsList(list)) {
//                return new ResultInfo("请填写完整的手机号再试");
//            }
//
//            for (int i = 0; i < list.size(); i++) {
//                if (ValidateUtil.isNotNull(tmpUsername)) {
//                    return new ResultInfo("账号不唯一 请输入完整账号");
//                }
//                CityPostman c = list.get(i);
//                if (null == c) {
//                    continue;
//                }
//                String cU = c.getUsername();
//                if (ValidateUtil.isNull(cU)) {
//                    continue;
//                }
//                if (toUsername.equalsIgnoreCase(cU.substring(cU.length() - toUsername.length()))) {
//                    tmpUsername = cU;
//                }
//            }
//            if (ValidateUtil.isNull(tmpUsername)) {
//                return new ResultInfo("未匹配到配送员，请填写完整手机号");
//            } else {
//                toUsername = tmpUsername;
//            }
//        }
//
//        //传入的配送员账号可能不准确
//        String fromUser = orderInfo.getPostManUsername();
//        if (ValidateUtil.isNotNull(fromUser)) {
//            fromUsername = fromUser;
//        }
//
//        if (fromUsername.equalsIgnoreCase(toUsername)) {
//            return new ResultInfo("您不可以将订单转给自己");
//        }
//
//        CityPostman fromPostman = CityPostmanMemory.getInstance().getPostman(fromUsername);
//        if (null == fromPostman) {
//            return new ResultInfo("发起者信息不存在");
//        }
//        CityPostman toPostman = CityPostmanMemory.getInstance().getPostman(toUsername);
//        if (null == toPostman) {
//            return new ResultInfo("接受者信息不存在");
//        }
//        if (0 == toPostman.getIsWork()) {
//            return new ResultInfo("对方未上班，无法转单");
//        }
//
//        if (ValidateUtil.isNotNull(orderInfo.getChangePostman())) {
//            return new ResultInfo("已发起转单，请等待对方操作");
//        }
//
//        if (!isSystem) {
//            //发起者今日发起次数
//            Long fromCount = 0l;
//            StringBuffer sb = new StringBuffer();
//            sb.append(" select count(1) as counts from ").append(PojoTables.ORDER_POSTMAN)
//                    .append(" where fromUsername = '").append(fromUsername).append("' and delFlag =0  ")
//                    .append(" and from_unixtime(createTime/1000,'%Y%m%d')=date_format(now(),'%Y%m%d') ");
//            try {
//                fromCount = UserDaoSql.getInstance().getCount(sb.toString());
//            } catch (SQLException e) {
//                e.printStackTrace();
//                return new ResultInfo("获取当前配送员转单数失败");
//            }
//
//            Integer canChangeCount = 2;
//            if (null != SYS_SETTINGS.POSTMAN_CAN_CHANGE_COUNT_PRE_DAY && SYS_SETTINGS.POSTMAN_CAN_CHANGE_COUNT_PRE_DAY >= 0) {
//                canChangeCount = SYS_SETTINGS.POSTMAN_CAN_CHANGE_COUNT_PRE_DAY;
//            }
//            if (fromCount >= canChangeCount) {
//                return new ResultInfo("今日转单次数达到上限，无法转单");
//            }
//        }
//
//
//        if (ValidateUtil.isNotNull(fromPostman.getCity()) && ValidateUtil.isNotNull(toPostman.getCity()) && !fromPostman.getCity().equalsIgnoreCase(toPostman.getCity())) {
//            return new ResultInfo("被转对象不在可转范围内，请更换");
//        }
//
//        //判断订单状态是否可以操作
//        if (ORDER_STATUS.OVER == orderInfo.getOrderStatus()
//                || ORDER_STATUS.SUBMIT == orderInfo.getOrderStatus()
//                || ORDER_STATUS.CANCEL == orderInfo.getOrderStatus()
//                || ORDER_STATUS.PAYED_CANCEL == orderInfo.getOrderStatus()
//                || ORDER_STATUS.CANCEL_BY_SYSTEM == orderInfo.getOrderStatus()
//                || ORDER_STATUS.SHOP_FINISH == orderInfo.getOrderStatus()
//                || ORDER_STATUS.SHOP_REFUSED == orderInfo.getOrderStatus()
//                || ORDER_STATUS.POSTMAN_FINISH == orderInfo.getOrderStatus()) {
//            return new ResultInfo("该状态不允许操作");
//        }
//
//        OrderPostmanInfo orderPostman = new OrderPostmanInfo();
//        orderPostman.setOrderNo(orderNo);
//        orderPostman.setFromId(fromPostman.getId());
//        orderPostman.setFromUsername(fromPostman.getUsername());
//        orderPostman.setToId(toPostman.getId());
//        orderPostman.setToUsername(toPostman.getUsername());
//        orderPostman.setCreateTime(DateUtils.getCurrTime());
//
//        orderPostman.setDelFlag(0);
//        orderPostman.setCreateUser(opUsername);
//
//        boolean isNeedAccept = true; // 骑手是否需要接单
//        if (!OrderMan.systemOperatePostmanNeedAccept()) {
//            isNeedAccept = false;
//            orderPostman.setIsSure(1);
//        } else {
//            orderPostman.setIsSure(0);
//        }
//
//        try {
//            UserDaoSql.getInstance().insertObj(PojoTables.ORDER_POSTMAN, orderPostman);
//        } catch (SQLException e) {
//            e.printStackTrace();
//            return new ResultInfo("转单失败，请稍后再试");
//        }
//        OrderInfoMemory.getInstance().changeToPostman(orderNo, toUsername);
//
//        Long time = DateUtils.getCurrTime();
//        //订单详情更改
//        StringBuffer sbOrder = new StringBuffer();
//        sbOrder.append("update ").append(PojoTables.OrderInfo).append(" set updateUser='").append(opUsername).append("'");
//        if (!isNeedAccept && isSystem) {
//            UserInfo toPost = UserInfoMemory.getInstance().getUserInfo(toUsername);
//            if (null == toPost) {
//                return new ResultInfo("被转用户不存在，请查证");
//            }
//
//            // 获取当前订单状态，继续当前骑手的订单状态往下走
//            sbOrder.append(",postmanSureTime=").append(time)
//                    .append(",postmanUsername='").append(toUsername).append("',postmanName='").append(toPost.getName())
//                    .append("',postmanPhone='").append(toPost.getTelPhone()).append("',postmanImageUrl='").append(toPost.getSignPhoto()).append("'");
//        } else {
//            sbOrder.append(",changePostman='").append(toUsername).append("'");
//        }
//        sbOrder.append(" where delFlag = 0 and orderNo = '").append(orderNo).append("'");
//        try {
//            UserDaoSql.getInstance().executeBySql(sbOrder.toString());
//            if (!isNeedAccept && isSystem) {
//                OrderStatus orderStatus2 = new OrderStatus(orderNo, ORDER_STATUS.POSTMAN_SURE, opUsername, time);
//                UserDaoSql.getInstance().insertObj(PojoTables.OrderStatus, orderStatus2);
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//            return new ResultInfo("转单失败，请稍后再试。");
//        }
//        OrderInfoMemory.getInstance().modifyStatus(orderNo);
//        if (!isNeedAccept && isSystem) {
//            OrderStatusMemory.getInstance().addStatus(orderNo);
//
//            // 将订单从上一个骑手的缓存中清楚
//            OrderInfoMemory.getInstance().removePostmanOrderInfo(fromUsername, orderNo);
//        }
//        return new ResultInfo();
//    }


}
